package ar.com.drconta.ganancias.editors.example;

import java.util.List;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

import ar.com.drconta.ganancias.editors.example.modelVO.City;
import ar.com.drconta.ganancias.editors.example.modelVO.House;
import ar.com.drconta.ganancias.editors.example.modelVO.Street;

class AddressContentProvider implements ITreeContentProvider{
      /**
	 * 
	 */
	private View AddressContentProvider;

	/**
	 * @param view
	 */
	AddressContentProvider(View view) {
		AddressContentProvider = view;
	}

	public Object[] getChildren(Object parentElement){
         if (parentElement instanceof List)
            return ((List<?>) parentElement).toArray();
         if (parentElement instanceof City)
            return ((City) parentElement).getStreets();
         if (parentElement instanceof Street)
            return ((Street) parentElement).getHouses();
         return new Object[0];
      }
 
      public Object getParent(Object element){
         if (element instanceof Street)
            return ((Street) element).city;
         if (element instanceof House)
            return ((House) element).street;
         return null;
      }
 
      public boolean hasChildren(Object element){
         if (element instanceof List)
            return ((List<?>) element).size() > 0;
         if (element instanceof City)
            return ((City) element).getStreets().length > 0;
         if (element instanceof Street)
            return ((Street) element).getHouses().length > 0;
         return false;
      }
 
      public Object[] getElements(Object cities){
         // cities ist das, was oben in setInput(..) gesetzt wurde.
         return getChildren(cities);
      }
 
      public void dispose(){
      }
 
      public void inputChanged(Viewer viewer, Object oldInput, Object newInput){
      }
   }